﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Pages/addressbook/list_view.master" %>

<script runat="server">
    void Page_Init(object o, EventArgs e)
    {
        if (null != Session["BranchID"])
        {
            ds2.FilterExpression = string.Format("BranchID={0} AND {1}", Session["BranchID"], Session["WhereClause"]);
        }
        else
        {
            ds2.FilterExpression = string.Format("{1}", Session["BranchID"], Session["WhereClause"]);
            //ds2.FilterExpression = string.Format("BranchID={0}", 0);
        }
        if (!IsPostBack)
        {
            ds2.FilterExpression = string.Format("BranchID={0}", 0);
        }


    }

    void Page_Load(object o, EventArgs e)
    {
        if (!IsPostBack)
        {
            grid1.FocusedRowIndex = -1;
        }
    }
    
    
    
    void clickme(object o, EventArgs e)
    {
        //System.Threading.Thread.Sleep(5000);
       // mylabel.Text = "click alrady";
       // timerbox.Text = DateTime.Now.ToString();
        
    }

    void MakeChanged(Object sender,  EventArgs e)
    {
        ASPxGridView grid = sender as ASPxGridView;

        int t = grid.FocusedRowIndex;
        if (t > -1)
        {
            object id = grid.GetRowValues(t, new string[] { "BranchID" });
            //object name = grid.GetRowValues(t, new string[] { "Name" });
            // mylabel.Text = "Selection:" + id.ToString();
            
            Session["BranchID"] = id;
            int idn = int.Parse(id.ToString());
            if (idn > 0)
            {
               
            } 
            
            ds2.FilterExpression = string.Format("BranchID={0}", Session["BranchID"]);

            grid2.Selection.UnselectAll();
            grid2.PageIndex = 0;
            grid2.DataBind();
            
            
            
            
            //this.dsXXModel.FilterExpression = "BranchID=" + o;
            //DataBind();
        }
    }


    protected void grid2_Init(object sender, EventArgs e)
    {
        ASPxGridView grd = sender as ASPxGridView;
        if (grd != null)
        {
            grd.ForceDataRowType(typeof(Touchmax.DdItem));
        }
    }

    protected void grid2_InitNewRow(object sender, DevExpress.Web.Data.ASPxDataInitNewRowEventArgs e)
    {
    }

    protected void grid2_RowUpdating(object sender, DevExpress.Web.Data.ASPxDataUpdatingEventArgs e)
    {
    }

    protected void grid2_RowInserting(object sender, DevExpress.Web.Data.ASPxDataInsertingEventArgs e)
    {
        int id = int.Parse(Session["BranchID"].ToString());
        e.NewValues["BranchID"] = id;

    }

    protected void btn_Search_Click(object sender, EventArgs e)
    {
        string name = this.txt_Name.Text.Trim().ToUpper();
        string where = "";
        if (name.Length > 0)
        {
            where = string.Format("Name LIKE '%{0}%' OR Tel1 Like '%{0}%' OR Fax1 Like '%{0}%' OR Email1 Like '%{0}%' OR Contact1 Like '%{0}%'", name);
        }

        this.ds2.FilterExpression = where;
        this.grid1.DataBind();
        Session["WhereClause"] = where;
    }



    #region customer
    protected void gridList_Init(object sender, EventArgs e)
    {
        ASPxGridView grd = sender as ASPxGridView;
        if (grd != null)
        {
            grd.ForceDataRowType(typeof(Touchmax.BoClient));
        }
    }

    protected void gridEdit_Init(object sender, EventArgs e)
    {
        ASPxGridView grd = sender as ASPxGridView;
        if (grd != null)
        {
            grd.ForceDataRowType(typeof(Touchmax.BoClient));
        }
    }


    protected void gridEdit_InitNewRow(object sender, DevExpress.Web.Data.ASPxDataInitNewRowEventArgs e)
    {

        e.NewValues["CustId"] = "0";
        e.NewValues["Address"] = " ";
        e.NewValues["Tel1"] = " ";
        e.NewValues["Tel2"] = " ";
        e.NewValues["Fax1"] = " ";
        e.NewValues["Fax2"] = " ";
        e.NewValues["Contact1"] = " ";
        e.NewValues["Contact2"] = " ";
        e.NewValues["Email1"] = " ";
        e.NewValues["Email2"] = " ";
        e.NewValues["Remark"] = " ";
        e.NewValues["NomInd"] = "N";
        e.NewValues["UeiNo"] = " ";

        string userId = HttpContext.Current.User.Identity.Name;
        e.NewValues["UserId"] = userId;
        e.NewValues["EntryDate"] = DateTime.Today;

    }
    protected void gridEdit_RowInserting(object sender, DevExpress.Web.Data.ASPxDataInsertingEventArgs e)
    {

        e.NewValues["CustId"] = GetNo("Cust").ToString();
        string userId = HttpContext.Current.User.Identity.Name;

        e.NewValues["UserId"] = userId;
        e.NewValues["EntryDate"] = DateTime.Today;
    }
    protected void gridEdit_RowInserted(object sender, DevExpress.Web.Data.ASPxDataInsertedEventArgs e)
    {
        if (e.Exception == null)
        {
            int custId = SafeValue.SafeInt(e.NewValues["CustId"], 0);
            if (custId > 0)
            {
                SetNewNo("Cust", custId);
            }
            Session["Cust"] = "CustId='" + custId + "'";
            this.dsEdit.FilterExpression = "CustId='" + custId + "'";
        }
    }
    protected void gridEdit_RowUpdating(object sender, DevExpress.Web.Data.ASPxDataUpdatingEventArgs e)
    {

    }
    protected void gridEdit_RowDeleting(object sender, DevExpress.Web.Data.ASPxDataDeletingEventArgs e)
    {

    }

    protected void gridEdit_CustomDataCallback(object sender, DevExpress.Web.ASPxGridView.ASPxGridViewCustomDataCallbackEventArgs e)
    {
        string n = e.Parameters;
        dsEdit.FilterExpression = "CustId='" + n + "'";
        gridEdit.DataBind();
        gridEdit.StartEdit(0);
        e.Result = n + " handled";
    }

    protected void gridEdit_CustomCallback(object sender, DevExpress.Web.ASPxGridView.ASPxGridViewCustomCallbackEventArgs e)
    {
        string n = e.Parameters;
        if (n == "Save")
        {
            ASPxPageControl pageControl = this.gridEdit.FindEditFormTemplateControl("pageControl") as ASPxPageControl;
            ASPxTextBox custIdCtr = pageControl.FindControl("ASPxTextBox6") as ASPxTextBox;
            // ASPxComboBox groupId = pageControl.FindControl("ASPxComboBox3") as ASPxComboBox;
            ASPxTextBox custName = pageControl.FindControl("ASPxTextBox1") as ASPxTextBox;
            ASPxTextBox custCode = pageControl.FindControl("ASPxTextBox23") as ASPxTextBox;
            ASPxMemo des = pageControl.FindControl("ASPxMemo1") as ASPxMemo;


            string userName = HttpContext.Current.User.Identity.Name;
            OPathQuery query = new OPathQuery(typeof(Touchmax.BoClient), "CustId='" + custIdCtr.Text + "'");
            Touchmax.BoClient cust = Touchmax.Manager.ORManager.GetObject(query) as Touchmax.BoClient;
            bool isNew = false;
            if (cust == null)
            {
                int custId = GetNo("CUSTOMER");

                isNew = true;
                cust = new Touchmax.BoClient();
                cust.CustId = custId.ToString();
                cust.UserId = HttpContext.Current.User.Identity.Name;
                cust.EntryDate = DateTime.Now;
            }
            cust.Code = custCode.Text;
            cust.Name = custName.Text;
            //cust.Remark = des.Text;
            try
            {
                if (isNew)
                {
                    Manager.ORManager.StartTracking(cust, Wilson.ORMapper.InitialState.Inserted);
                    Manager.ORManager.PersistChanges(cust);
                    SetNewNo("CUSTOMER", SafeValue.SafeInt(cust.CustId, 0));
                }
                else
                {
                    Manager.ORManager.StartTracking(cust, Wilson.ORMapper.InitialState.Updated);
                    Manager.ORManager.PersistChanges(cust);
                }
            }
            catch
            {
            }
            Session["CustWhere"] = "CustId='" + cust.CustId + "'";
            this.dsEdit.FilterExpression = Session["CustWhere"].ToString();
            if (this.gridEdit.GetRow(0) != null)
                this.gridEdit.StartEdit(0);
        }
        else
        {
            string[] cmd = n.Split(new char[] { '#' });
            if (cmd[0] == "Edit")
            {
                dsEdit.FilterExpression = "CustId='" + cmd[1] + "'";
                gridEdit.DataBind();
                gridEdit.StartEdit(0);
            }
        }
    }



    public int GetNo(string counter_id)
    {
        string sql_ivNo = "select COUNTER from XXSETUP where CATEGORY='" + counter_id + "'";
        int _InvN = SafeValue.SafeInt(Touchmax.Manager.ORManager.ExecuteScalar(sql_ivNo), 0) + 1;
        return _InvN;
    }
    public void SetNewNo(string counter_id, int oldNo)
    {
        string sql_updateInvoiceN = string.Format("update xxsetup set COUNTER='{0}' where category='{1}'", oldNo, counter_id);
        int flag = Touchmax.Manager.ORManager.ExecuteCommand(sql_updateInvoiceN);
    }
    #endregion

    #region Employee
    protected void grd_Cont_Init(object sender, EventArgs e)
    {
        ASPxGridView grd = sender as ASPxGridView;
        if (grd != null)
        {
            grd.ForceDataRowType(typeof(Touchmax.BoClientContact));
        }
    }
    protected void grd_Cont_BeforePerformDataSelect(object sender, EventArgs e)
    {
        ASPxGridView grd = sender as ASPxGridView;
        if (grd != null && grd.GetMasterRowKeyValue() != null)
        {
            string custid = grd.GetMasterRowKeyValue().ToString();
            this.dsEmployee.FilterExpression = "CompanyId='" + custid + "'";// 

        }
    }
    protected void grd_Cont_InitNewRow(object sender, DevExpress.Web.Data.ASPxDataInitNewRowEventArgs e)
    {
        //string oid = (sender as ASPxGridView).GetMasterRowKeyValue().ToString();
        //e.NewValues["ContNo"] = "";// order.ContNo;
        //e.NewValues["SealNo"] = "";//order.SealNo;
        //e.NewValues["Ft20"] = 0;
        //e.NewValues["Ft40"] = 0;
        //e.NewValues["Ft45"] = 0;
        //e.NewValues["FtType"] = "GP";
        //e.NewValues["ContStatus"] = "PENDING";
        //e.NewValues["ScheduleDate"] = new DateTime(1900,1,1);
        //e.NewValues["ScheduleTime"] = " ";
    }
    protected void grd_Cont_RowInserting(object sender, DevExpress.Web.Data.ASPxDataInsertingEventArgs e)
    {
        string custId = (sender as ASPxGridView).GetMasterRowKeyValue().ToString();
        e.NewValues["CompanyId"] = custId;
        e.NewValues["EmployeeId"] = GetNo("Employee");
        e.NewValues["UserId"] = HttpContext.Current.User.Identity.Name;
        e.NewValues["EntryDate"] = DateTime.Now;
    }
    protected void grd_Cont_RowUpdating(object sender, DevExpress.Web.Data.ASPxDataUpdatingEventArgs e)
    { }
    protected void grd_Cont_RowInserted(object sender, DevExpress.Web.Data.ASPxDataInsertedEventArgs e)
    {
        if (e.Exception == null)
        {
            SetNewNo("Employee", SafeValue.SafeInt(e.NewValues["EmployeeId"], 0));
        }
    }
    protected void grd_Cont_RowUpdated(object sender, DevExpress.Web.Data.ASPxDataUpdatedEventArgs e)
    {

    }
    #endregion
    
    
    
    </script>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
    <style>
    div {font-size:10px;font-family:Verdana;}
    </style>
    <script type="text/javascript">

        function Edit(n, t) {
            if (t == "RETAIL") {
              //  window.frames["preview"].location = "/pages/addressbook/retailedit.aspx?n=" + n;
                gridEdit.PerformCallback("Edit#" + n);

            } else {
              //  window.frames["preview"].location = "/pages/addressbook/dealeredit.aspx?n=" + n;
                gridEdit.PerformCallback("Edit#" + n);
            } 
        }


    </script>
</asp:Content>

<asp:Content ID="title1" ContentPlaceHolderID="Title1" Runat="Server">
<table width=100% cellpadding="4">
    <tr>
    <td align=left class="bb">
        Branch List
    </td>
</tr>
</table>
</asp:Content>
<asp:Content ID="title2" ContentPlaceHolderID="Title2" Runat="Server">
<table width=100% cellpadding="2">
    <tr>
    <td align=left class="bb" width="*">
        Client Search
    </td>
    <td align=right class="bb">
       
    </td>
    </tr>
</table>
</asp:Content>
<asp:Content ID="title3" ContentPlaceHolderID="Title3" Runat="Server">
<table width=100% cellpadding="2">
    <tr>
    <td align=left class="bb">
        Client Details
    </td>
    </tr>
</table>
</asp:Content>

<asp:Content ID="Page1" ContentPlaceHolderID="Page1" Runat="Server">
<wilson:DataSource ID="ds1" TypeName="Touchmax.BoBranch" KeyMember="BranchID" FilterExpression="1=1" runat="server" ObjectSpace="Touchmax.Manager.ORManager"/>
    <wilson:DataSource ID="dsList" runat="server" ObjectSpace="Touchmax.Manager.ORManager" TypeName="Touchmax.BoClient" KeyMember="CustId" FilterExpression="1=1" />
 <dxwgv:ASPxGridView ID="grid1" ClientInstanceName="grid1" runat="server" DataSourceID="ds1" KeyFieldName="BranchID" 
       OnFocusedRowChanged="MakeChanged" Width="100%" AutoGenerateColumns="False" EnableCallBacks="False">
                <SettingsPager Mode="ShowAllRecords"/>
                <Columns>
                    <dxwgv:GridViewDataColumn FieldName="BranchName" VisibleIndex="1" SortIndex="1" SortOrder="Descending">
                    </dxwgv:GridViewDataColumn>
                </Columns>
                <Settings ShowGroupPanel="False" ShowFooter="False" ShowTitlePanel="false" ShowColumnHeaders="False" />
                <SettingsBehavior AllowMultiSelection="false" AllowFocusedRow="true" ProcessFocusedRowChangedOnServer="true" />
            </dxwgv:ASPxGridView>
</asp:Content>
<asp:Content ID="Page2" ContentPlaceHolderID="Page2" Runat="Server">

<asp:SqlDataSource ID="dsPickColorFormular"	SelectCommand="select ddItemCode as Code, ddItemId as Id from ddItems where ddItemStatus='Active' and ddGroupId=1001 order by ddItemSort" runat="server" ConnectionString="Server=.\Sqlexpress;DataBase=colorworksDB;UID=sa;PWD=1234;"  />
<asp:SqlDataSource ID="dsPickColorMatch" SelectCommand="select ddItemCode as Code, ddItemId as Id from ddItems where ddItemStatus='Active' and ddGroupId=1002 order by ddItemSort" runat="server" ConnectionString="Server=.\Sqlexpress;DataBase=colorworksDB;UID=sa;PWD=1234;"  />
<asp:SqlDataSource ID="dsPickMarketingSource" SelectCommand="select ddItemCode as Code, ddItemId as Id from ddItems where ddItemStatus='Active' and ddGroupId=1003 order by ddItemSort" runat="server" ConnectionString="Server=.\Sqlexpress;DataBase=colorworksDB;UID=sa;PWD=1234;"  />
<asp:SqlDataSource ID="dsPickOrderStatus" SelectCommand="select ddItemCode as Code, ddItemId as Id from ddItems where ddItemStatus='Active' and ddGroupId=1004 order by ddItemSort" runat="server" ConnectionString="Server=.\Sqlexpress;DataBase=colorworksDB;UID=sa;PWD=1234;"  />
<asp:SqlDataSource ID="dsPickColorOption" SelectCommand="select ddItemCode as Code, ddItemId as Id from ddItems where ddItemStatus='Active' and ddGroupId=1005 order by ddItemSort" runat="server" ConnectionString="Server=.\Sqlexpress;DataBase=colorworksDB;UID=sa;PWD=1234;"  />
<asp:SqlDataSource ID="dsPickDepartment" SelectCommand="select ddItemCode as Code, ddItemId as Id from ddItems where ddItemStatus='Active' and ddGroupId=1006 order by ddItemSort" runat="server" ConnectionString="Server=.\Sqlexpress;DataBase=colorworksDB;UID=sa;PWD=1234;"  />
<asp:SqlDataSource ID="dsPickWorkType" SelectCommand="select ddItemCode as Code, ddItemId as Id from ddItems where ddItemStatus='Active' and ddGroupId=1007 order by ddItemSort" runat="server" ConnectionString="Server=.\Sqlexpress;DataBase=colorworksDB;UID=sa;PWD=1234;"  />
<asp:SqlDataSource ID="dsPickWorkLocation" SelectCommand="select ddItemCode as Code, ddItemId as Id from ddItems where ddItemStatus='Active' and ddGroupId=1008 order by ddItemSort" runat="server" ConnectionString="Server=.\Sqlexpress;DataBase=colorworksDB;UID=sa;PWD=1234;"  />
<asp:SqlDataSource ID="dsPickServiceType" SelectCommand="select ddItemCode as Code, ddItemId as Id from ddItems where ddItemStatus='Active' and ddGroupId=1009 order by ddItemSort" runat="server" ConnectionString="Server=.\Sqlexpress;DataBase=colorworksDB;UID=sa;PWD=1234;"  />
<asp:SqlDataSource ID="dsPickRepairStatus" SelectCommand="select ddItemCode as Code, ddItemId as Id from ddItems where ddItemStatus='Active' and ddGroupId=1010 order by ddItemSort" runat="server" ConnectionString="Server=.\Sqlexpress;DataBase=colorworksDB;UID=sa;PWD=1234;"  />
<asp:SqlDataSource ID="dsPickCustomerGroup" SelectCommand="select ddItemCode as Code, ddItemId as Id from ddItems where ddItemStatus='Active' and ddGroupId=1011 order by ddItemSort" runat="server" ConnectionString="Server=.\Sqlexpress;DataBase=colorworksDB;UID=sa;PWD=1234;"  />
<asp:SqlDataSource ID="dsPickPrimaryColor" SelectCommand="select ddItemCode as Code, ddItemId as Id from ddItems where ddItemStatus='Active' and ddGroupId=1012 order by ddItemSort" runat="server" ConnectionString="Server=.\Sqlexpress;DataBase=colorworksDB;UID=sa;PWD=1234;"  />
<asp:SqlDataSource ID="dsPickBranchGroupID" SelectCommand="select ddItemCode as Code, ddItemId as Id from ddItems where ddItemStatus='Active' and ddGroupId=1013 order by ddItemSort" runat="server" ConnectionString="Server=.\Sqlexpress;DataBase=colorworksDB;UID=sa;PWD=1234;"  />
<asp:SqlDataSource ID="SqlDataSource1" SelectCommand="select ddItemCode as Code, ddItemId as Id from ddItems where ddItemStatus='Active' and ddGroupId=1014 order by ddItemSort" runat="server" ConnectionString="Server=.\Sqlexpress;DataBase=colorworksDB;UID=sa;PWD=1234;"  />
<asp:SqlDataSource ID="dsPickPhoneType" SelectCommand="select ddItemCode as Code, ddItemId as Id from ddItems where ddItemStatus='Active' and ddGroupId=1015 order by ddItemSort" runat="server" ConnectionString="Server=.\Sqlexpress;DataBase=colorworksDB;UID=sa;PWD=1234;"  />
<asp:SqlDataSource ID="dsPickBranchStatusID" SelectCommand="select ddItemCode as Code, ddItemId as Id from ddItems where ddItemStatus='Active' and ddGroupId=1016 order by ddItemSort" runat="server" ConnectionString="Server=.\Sqlexpress;DataBase=colorworksDB;UID=sa;PWD=1234;"  />
<asp:SqlDataSource ID="dsPickEmploymentStatusID" SelectCommand="select ddItemCode as Code, ddItemId as Id from ddItems where ddItemStatus='Active' and ddGroupId=1017 order by ddItemSort" runat="server" ConnectionString="Server=.\Sqlexpress;DataBase=colorworksDB;UID=sa;PWD=1234;"  />
<asp:SqlDataSource ID="dsPickPaymentTerm" SelectCommand="select ddItemCode as Code, ddItemId as Id from ddItems where ddItemStatus='Active' and ddGroupId=1018 order by ddItemSort" runat="server" ConnectionString="Server=.\Sqlexpress;DataBase=colorworksDB;UID=sa;PWD=1234;"  />
<asp:SqlDataSource ID="dsPickVehicleYear" SelectCommand="select ddItemCode as Code, ddItemId as Id from ddItems where ddItemStatus='Active' and ddGroupId=1019 order by ddItemSort" runat="server" ConnectionString="Server=.\Sqlexpress;DataBase=colorworksDB;UID=sa;PWD=1234;"  />
<asp:SqlDataSource ID="dsPickPaymentMethod" SelectCommand="select ddItemCode as Code, ddItemId as Id from ddItems where ddItemStatus='Active' and ddGroupId=1020 order by ddItemSort" runat="server" ConnectionString="Server=.\Sqlexpress;DataBase=colorworksDB;UID=sa;PWD=1234;"  />
<asp:SqlDataSource ID="dsPickCallProcess" SelectCommand="select ddItemCode as Code, ddItemId as Id from ddItems where ddItemStatus='Active' and ddGroupId=1021 order by ddItemSort" runat="server" ConnectionString="Server=.\Sqlexpress;DataBase=colorworksDB;UID=sa;PWD=1234;"  />
<asp:SqlDataSource ID="dsPickCallStatus" SelectCommand="select ddItemCode as Code, ddItemId as Id from ddItems where ddItemStatus='Active' and ddGroupId=1022 order by ddItemSort" runat="server" ConnectionString="Server=.\Sqlexpress;DataBase=colorworksDB;UID=sa;PWD=1234;"  />


<asp:SqlDataSource ID="dsPickCountry" SelectCommand="select * from ddCountry order by countryname" runat="server" ConnectionString="Server=.\Sqlexpress;DataBase=colorworksDB;UID=sa;PWD=1234;"  />
<asp:SqlDataSource ID="dsPickState" SelectCommand="select * from ddState where countrycode='CA' order by statename" runat="server" ConnectionString="Server=.\Sqlexpress;DataBase=colorworksDB;UID=sa;PWD=1234;"  />
<asp:SqlDataSource ID="dsPickCity" SelectCommand="select * from ddCity where statecode='BC' order by statename" runat="server" ConnectionString="Server=.\Sqlexpress;DataBase=colorworksDB;UID=sa;PWD=1234;"  />
<asp:SqlDataSource ID="dsPickZoneCode" SelectCommand="select distinct zonecode from ddPostal order by zonename" runat="server" ConnectionString="Server=.\Sqlexpress;DataBase=colorworksDB;UID=sa;PWD=1234;"  />


<asp:SqlDataSource ID="dsPickRoleID" SelectCommand="select RoleName as Code, RoleID as Id from acRole" runat="server" ConnectionString="Server=.\Sqlexpress;DataBase=colorworksDB;UID=sa;PWD=1234;"  />
<asp:SqlDataSource ID="dsPickEmployeeGroupID" SelectCommand="select ddItemCode as Code, ddItemId as Id from ddItems where ddItemStatus='Active' and ddGroupId=1014 order by ddItemSort" runat="server" ConnectionString="Server=.\Sqlexpress;DataBase=colorworksDB;UID=sa;PWD=1234;"  />
<wilson:DataSource ID="dsBranch" TypeName="Touchmax.BoBranch" KeyMember="BranchID" FilterExpression="1=1" runat="server" ObjectSpace="Touchmax.Manager.ORManager"/>
<wilson:DataSource ID="dsCombo" TypeName="Touchmax.FaItem" KeyMember="ItemID" FilterExpression="1=1" runat="server" ObjectSpace="Touchmax.Manager.ORManager"/>

<wilson:DataSource ID="ds2" runat="server" ObjectSpace="Touchmax.Manager.ORManager" TypeName="Touchmax.BoClient" KeyMember="CustId" FilterExpression="1=1" />

<div style="background:#eeeeee">
<table cellpadding=2 width="100%">
<tr>
    <td width="*">
    </td>
         <td width=130>
                        <dxe:ASPxTextBox ID="txt_Name" Width="120" runat="server">
                        </dxe:ASPxTextBox>
            </td>
            <td width=70>
                        <dxe:ASPxButton ID="btn_Search" Width="65" runat="server" Text="Search" OnClick="btn_Search_Click">
                        </dxe:ASPxButton>
            </td>
</tr>
</table>
</div>
<dxwgv:ASPxGridView ID="grid2" ClientInstanceName="grid2" runat="server" DataSourceID="ds2" KeyFieldName="CustId" 
        Width="100%" AutoGenerateColumns="False"  EnableCallBacks="False" OnInit="grid2_Init" OnInitNewRow="grid2_InitNewRow" OnRowUpdating="grid2_RowUpdating" OnRowInserting="grid2_RowInserting">
                <SettingsPager Mode="ShowAllRecords"/>
                <Columns>

                <dxwgv:GridViewDataTextColumn Caption="Code" FieldName="CustId" VisibleIndex="1" Width="60">
                </dxwgv:GridViewDataTextColumn>
                <dxwgv:GridViewDataTextColumn Caption="Name" FieldName="Name" VisibleIndex="2">
                <DataItemTemplate>
                    
                    <a href="javascript:Edit(<%# Eval("CustId") %>,'<%# Eval("GroupId") %>')"><%# Eval("Name") %></a>
                </DataItemTemplate>
                </dxwgv:GridViewDataTextColumn>
                <dxwgv:GridViewDataTextColumn Caption="Tel" FieldName="Tel1" VisibleIndex="3">
                </dxwgv:GridViewDataTextColumn>
                <dxwgv:GridViewDataTextColumn Caption="Fax" FieldName="Fax1" VisibleIndex="4">
                </dxwgv:GridViewDataTextColumn>
                <dxwgv:GridViewDataTextColumn Caption="Email" FieldName="Email1" VisibleIndex="5">
                </dxwgv:GridViewDataTextColumn>

                    </Columns>
 
      
                <Settings ShowGroupPanel="False" ShowFooter="False" ShowTitlePanel="false" ShowColumnHeaders="True" />
                <SettingsBehavior ConfirmDelete="True" AllowFocusedRow="true" ProcessFocusedRowChangedOnServer="false" />
            </dxwgv:ASPxGridView>
</asp:Content>
<asp:Content ID="Page3" ContentPlaceHolderID="Page3" Runat="Server">
<div style="background:#eeeeee">
<table cellpadding=2 width="100%">
<tr>
    <td width=110 align="left">
                    <dxe:ASPxButton ID="ASPxButton1" Width="100" runat="server" Text="New Client" AutoPostBack="false">
                        <ClientSideEvents Click="function(s,e){
                                gridEdit.AddNewRow();
                                }" />
                    </dxe:ASPxButton>
        </td>
    <td width="*">
    </td>
        <td width=110 align="right">

                    <dxe:ASPxButton ID="ASPxButton3" Width="100" runat="server" Text="Save Client" AutoPostBack="false">
                        <ClientSideEvents Click="function(s,e){
                                gridEdit.PerformCallback('Save');
                                }" />
                    </dxe:ASPxButton>
                </td></tr>
</table>
</div>
    <wilson:DataSource ID="dsEdit" runat="server" ObjectSpace="Touchmax.Manager.ORManager" TypeName="Touchmax.BoClient" KeyMember="CustId" FilterExpression="1=0" />
    <wilson:DataSource ID="dsEmployee" runat="server" ObjectSpace="Touchmax.Manager.ORManager" TypeName="Touchmax.BoClientContact" KeyMember="EmployeeId" FilterExpression="1=0" />


                <dxwgv:ASPxGridView ID="gridEdit" ClientInstanceName="gridEdit" runat="server" DataSourceID="dsEdit"
            Width="550" KeyFieldName="CustId" AutoGenerateColumns="False" OnInit="gridEdit_Init" EnableCallBacks="False"
            OnInitNewRow="gridEdit_InitNewRow" OnRowInserting="gridEdit_RowInserting"
            OnRowInserted="gridEdit_RowInserted" OnRowUpdating="gridEdit_RowUpdating"
            OnRowDeleting="gridEdit_RowDeleting" OnCustomDataCallback="gridEdit_CustomDataCallback" OnCustomCallback="gridEdit_CustomCallback">
            <SettingsPager PageSize="1">
            </SettingsPager>
            <SettingsEditing Mode="EditForm" />
            <Settings ShowFilterRow="false" ShowFooter="false" ShowTitlePanel="true" ShowColumnHeaders="false"   />
            <SettingsBehavior ConfirmDelete="True" />
            <Columns>
                    <dxwgv:GridViewCommandColumn Width="100">
                    <EditButton Visible="True" />
                    <DeleteButton Visible="true" />
                </dxwgv:GridViewCommandColumn>
                <dxwgv:GridViewDataTextColumn Caption="Id" FieldName="CustId" VisibleIndex="1" Width="100">
                </dxwgv:GridViewDataTextColumn>
                <dxwgv:GridViewDataTextColumn Caption="Name" FieldName="Name" VisibleIndex="2">
                </dxwgv:GridViewDataTextColumn>
            </Columns>
            <Templates>
                <EditForm>
                     <dxtc:ASPxPageControl runat="server" ID="pageControl" width="100%">
                        <tabpages>
                                
                                 <dxtc:TabPage Text="Client Information" Name="Sch" Visible="true">
                                    <ContentCollection>
                                        <dxw:ContentControl ID="ContentControl1" runat="server">
                   <div style="padding: 4px 4px 3px 4px">
                        <table width="500" cellpadding="2">
                            <tr>
                                <td width=70>
                                    Client Code
                                </td>
                                <td width=150>
                                <dxe:ASPxTextBox ID="ASPxTextBox6" ReadOnly="true" runat="server" Width="80%" Value='<%# Eval("CustId") %>'>
                                </dxe:ASPxTextBox>
                                </td>
                                <td width=70>
                                    Client Type
                                </td>
                                <td align="right" width="150">
                                <dxe:ASPxComboBox ID="ASPxComboBox2" Value='<%# Bind("GroupId") %>' Width="90" runat="server" >
                                                    <Items>
                                                    <dxe:ListEditItem Text="Retail" Value="RETAIL" />
                                                    <dxe:ListEditItem Text="Dealer" Value="DEALER" />
                                                    <dxe:ListEditItem Text="Rental" Value="RENTAL" />
                                                    <dxe:ListEditItem Text="Insurance" Value="INSURANCE" />
                                                    </Items>
                                </dxe:ASPxComboBox>
                                
                                </td>
                            <tr>
                            <tr>
                                <td>
                                    Client Name
                                </td>
                                <td colspan="3">
                                    <dxe:ASPxTextBox ID="ASPxTextBox1" runat="server" Width="100%" Value='<%# Eval("Name") %>'>
                                    </dxe:ASPxTextBox>
                                </td>
                            </tr>
                            <tr>
                            <td colspan="4">
                            <hr />
                            </td>
                            </tr>
                            <tr>
                                <td>
                                    Service Address
                                </td>
                                <td colspan="3">
                                    <dxe:ASPxTextBox ID="ASPxTextBox3" runat="server" Width="100%" Value='<%# Bind("Address1") %>'>
                                    </dxe:ASPxTextBox>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    
                                </td>
                                <td colspan="3">
                                    <dxe:ASPxTextBox ID="ASPxTextBox2" runat="server" Width="100%" Value='<%# Bind("Address2") %>'>
                                    </dxe:ASPxTextBox>
                                </td>
                            </tr>
                            <tr>
                            <td>City</td>
                            <td>
                                    <dxe:ASPxTextBox ID="ASPxTextBox4" runat="server" Value='<%# Bind("CityName") %>' Width="100%" >
                                    </dxe:ASPxTextBox></td>
                             <td>Province</td><td>

                             <table border=0 cellspacing=0 cellpadding=0>
                             <tr>
                             <td width=50>
                             <dxe:ASPxTextBox ID="ASPxTextBox5" runat="server" Value='<%# Bind("ProvinceCode") %>' Width="100%" >
                             </dxe:ASPxTextBox>
                             </td>
                             <td width=50>&nbsp;&nbsp;Postal</td>
                             <td width=60>
                             <dxe:ASPxTextBox ID="ASPxTextBox31" runat="server" Value='<%# Bind("PostalCode") %>' Width="100%" >
                             </dxe:ASPxTextBox>
                             </td>
                             </tr>
                             </table>

                                    </td></tr>
                            <tr>
                                <td>
                                    Telephone
                                </td>
                                <td>
                                    <dxe:ASPxTextBox ID="ASPxTextBox8" runat="server" Width="100%" Value='<%# Bind("Tel1") %>'>
                                    </dxe:ASPxTextBox>
                                </td>
                                <td>
                                    Fax
                                </td>
                                <td>
                                    <dxe:ASPxTextBox ID="ASPxTextBox9" runat="server" Width="100%" Value='<%# Bind("Fax1") %>'>
                                    </dxe:ASPxTextBox>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                </td>
                                <td>
                                    <dxe:ASPxTextBox ID="ASPxTextBox12" runat="server" Width="100%" Value='<%# Bind("Tel2") %>'>
                                    </dxe:ASPxTextBox>
                                </td>
                                <td>
                                </td>
                                <td>
                                    <dxe:ASPxTextBox ID="ASPxTextBox13" runat="server" Width="100%" Value='<%# Bind("Fax2") %>'>
                                    </dxe:ASPxTextBox>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    Primary Contact
                                </td>
                                <td>
                                    <dxe:ASPxTextBox ID="ASPxTextBox10" runat="server" Width="100%" Value='<%# Eval("Contact1") %>'>
                                    </dxe:ASPxTextBox>
                                </td>
                                <td>
                                    Email
                                </td>
                                <td>
                                    <dxe:ASPxTextBox ID="ASPxTextBox11" runat="server" Width="100%" Value='<%# Eval("Email1") %>'>
                                    </dxe:ASPxTextBox>
                                </td>
                            </tr>
                            <tr>
                            <td colspan="4">
                            <hr />
                            </td>
                            </tr>
                            
                            <tr>
                                <td>
                                    Bill Address
                                </td>
                                <td colspan="3">
                                    <dxe:ASPxTextBox ID="ASPxTextBox23" runat="server" Width="100%" Value='<%# Bind("Address3") %>'>
                                    </dxe:ASPxTextBox>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    
                                </td>
                                <td colspan="3">
                                    <dxe:ASPxTextBox ID="ASPxTextBox30" runat="server" Width="100%" Value='<%# Bind("Address4") %>'>
                                    </dxe:ASPxTextBox>
                                </td>
                            </tr>
                            <tr>
                            <td>City</td>
                            <td>
                                    <dxe:ASPxTextBox ID="ASPxTextBox19" runat="server" Value='<%# Bind("CityName2") %>' Width="100%" >
                                    </dxe:ASPxTextBox></td>
                             <td>Province</td><td>

                             <table border=0 cellspacing=0 cellpadding=0>
                             <tr>
                             <td width=50>
                             <dxe:ASPxTextBox ID="ASPxTextBox20" runat="server" Value='<%# Bind("ProvinceCode2") %>' Width="100%" >
                             </dxe:ASPxTextBox>
                             </td>
                             <td width=50>&nbsp;&nbsp;Postal</td>
                             <td width=60>
                             <dxe:ASPxTextBox ID="ASPxTextBox22" runat="server" Value='<%# Bind("PostalCode2") %>' Width="100%" >
                             </dxe:ASPxTextBox>
                             </td>
                             </tr>
                             </table>

                                    </td></tr>
       
                            <tr>
                            <td colspan="4">
                            <hr />
                            </td>
                            </tr>
                            <tr>
                                <td>
                                    Remarks
                                </td>
                                <td colspan="3">
                                    <dxe:ASPxMemo ID="ASPxTextBox18" Rows="3" runat="server" Width="100%" Value='<%# Eval("Remark") %>'>
                                    </dxe:ASPxMemo>
                            </tr>
                             <tr>
                            <tr>
                                <td>
                                   Updated by
                                </td>
                                <td>
                                
                                    <table><tr>
                                    <td><dxe:ASPxTextBox ID="ASPxTextBox14" runat="server" Width="60" Text='<%# Eval("UserId") %>' ReadOnly="true" BackColor="Control">
                                        </dxe:ASPxTextBox>
                                    </td>
                                    <td><dxe:ASPxTextBox ID="ASPxTextBox15" runat="server" Width="100" Text='<%# Eval("EntryDate","{0:dd/MM/yyyy HH:mm}") %>' ReadOnly="true" BackColor="Control">
                                        </dxe:ASPxTextBox>
                                    </td>
                                     </tr></table>
                                 </td>
                                 <td align="right" colspan=2>
                                    <table>
                                    <tr>
                                    <td align=right width=100>

                                <dxe:ASPxButton ID="btn_Save" Width="80" runat="server" Text="Save" AutoPostBack="false">
                                <ClientSideEvents Click="function(s,e){
                                gridEdit.PerformCallback('Save');
                                }" />
                                </dxe:ASPxButton>

                                    </td>
                                    <td align=right width=100>

                                   <%-- <dxe:ASPxButton ID="ASPxButton2" Width="80" runat="server" Text="Cancel" AutoPostBack="false">
                                <ClientSideEvents Click="function(s,e){
                                gridEdit.CancelEdit();
                                }" />
                                </dxe:ASPxButton>--%>

                                    </td>
                                    
                                    </tr>
                                    </table>
                                 </td>
                            <tr>
                            <td colspan="2"></td>
                                <td style="text-align: right; padding: 2px 2px 2px 2px">
                                </td>
                                <td style="text-align: right; padding: 2px 2px 2px 2px">
                                
                                </td>
                            </tr>
                        </table>
                    </div>
                                       </dxw:ContentControl>
                                    </ContentCollection>
                                </dxtc:TabPage>
                                 <dxtc:TabPage Text="Client Contacts" Name="Employee " Visible="true">
                                    <ContentCollection>
                                        <dxw:ContentControl ID="ContentControl12" runat="server">
                                                                         
                                            <dxwgv:ASPxGridView ID="grd_Cont" ClientInstanceName="grd_Cont" runat="server"
                                                DataSourceID="dsEmployee" KeyFieldName="EmployeeId" Width="100%"
                                                            OnBeforePerformDataSelect="grd_Cont_BeforePerformDataSelect"  
                                                            oninit="grd_Cont_Init"
                                                            OnInitNewRow="grd_Cont_InitNewRow" OnRowInserting="grd_Cont_RowInserting"
                                                            OnRowUpdating="grd_Cont_RowUpdating" 
                                                            onrowinserted="grd_Cont_RowInserted" 
                                                            onrowupdated="grd_Cont_RowUpdated">
                                                            <SettingsBehavior ConfirmDelete="True" />
                                                            <SettingsPager Mode="ShowAllRecords">
                                                            </SettingsPager>
                                                            <SettingsEditing Mode="EditForm" />
                                                <Columns>
                                                    <dxwgv:GridViewCommandColumn VisibleIndex="0" width="5%">
                                                        <EditButton Text="Edit" Visible="True" />
                                                    </dxwgv:GridViewCommandColumn>
                                                    <dxwgv:GridViewCommandColumn width="5%">
                                                        <DeleteButton Visible="true" />
                                                    </dxwgv:GridViewCommandColumn>
                                                                <dxwgv:GridViewDataColumn FieldName="FullName" Caption="FirstName" VisibleIndex="1" Width="70">
                                                                </dxwgv:GridViewDataColumn>
                                                                <dxwgv:GridViewDataColumn FieldName="JobTitle" Caption="JobTitle" VisibleIndex="1" Width="70">
                                                                </dxwgv:GridViewDataColumn>
                                                                <dxwgv:GridViewDataColumn FieldName="Department" Caption="Department" VisibleIndex="1" Width="70">
                                                                </dxwgv:GridViewDataColumn>
                                                                <dxwgv:GridViewDataColumn FieldName="Tel" Caption="Tel" VisibleIndex="1" Width="70">
                                                                </dxwgv:GridViewDataColumn>
                                                                <dxwgv:GridViewDataColumn FieldName="Mobile" Caption="Mobile" VisibleIndex="1" Width="70">
                                                                </dxwgv:GridViewDataColumn>
                                                </Columns>
                                                <Templates>
                                                <EditForm>
                                                        <table style="text-align: right; padding: 2px 2px 2px 2px;width:600">
                                                        <tr>
                                                        <td width="70%">
                                                                    </td><td>
                                                                    <dxe:ASPxButton ID="ASPxButton4" Width="100" runat="server" Text="Save & Close"  AutoPostBack="false" UseSubmitBehavior="false" >
                                                                    <ClientSideEvents Click="function(s,e) {
                                                                    grd_Cont.UpdateEdit();
                                                                    }" />
                                                                    </dxe:ASPxButton></td><td>
                                                                    <dxe:ASPxButton ID="ASPxButton5" Width="100" runat="server" Text="Close" AutoPostBack="false" UseSubmitBehavior="false" >
                                                                    <ClientSideEvents Click="function(s,e) {
                                                                    grd_Cont.CancelEdit();
                                                                    }" />
                                                                    </dxe:ASPxButton>
                                                           </td></tr>
                                                        </table>
                                                 <table>
                        <tr>
                            <td>
                                First Name
                            </td>
                            <td>
                                <dxe:ASPxTextBox ID="ASPxTextBox15" Width="140" runat="server" Text='<%# Bind("FirstName")%>'>
                                </dxe:ASPxTextBox>
                            </td>
                            <td>
                                Middle Name
                            </td>
                            <td>
                                <dxe:ASPxTextBox ID="ASPxTextBox16" Width="140" runat="server" Text='<%# Bind("MiddleName")%>'>
                                </dxe:ASPxTextBox>
                            </td>
                            <td>
                                Last Name
                            </td>
                            <td>
                                <dxe:ASPxTextBox ID="ASPxTextBox161" Width="140" runat="server" Text='<%# Bind("LastName")%>'>
                                </dxe:ASPxTextBox>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                Tel
                            </td>
                            <td>
                                <dxe:ASPxTextBox ID="ASPxTextBox17" Width="140"
                                    runat="server" Text='<%# Bind("Tel")%>'>
                                </dxe:ASPxTextBox>
                            </td>
                            <td>
                                Fax
                            </td>
                            <td>
                                <dxe:ASPxTextBox ID="ASPxTextBox18" Width="140"
                                    runat="server" Text='<%# Bind("Fax")%>'>
                                </dxe:ASPxTextBox>
                            </td>
                            <td>
                                Email
                            </td>
                            <td>
                                <dxe:ASPxTextBox ID="ASPxTextBox19" Width="140" ClientInstanceName="txt_InvNo" runat="server"
                                     Text='<%# Bind("Email")%>'>
                                </dxe:ASPxTextBox>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                Phone
                            </td>
                            <td>
                                <dxe:ASPxTextBox ID="ASPxTextBox20" Width="140"
                                    runat="server" Text='<%# Bind("Mobile")%>'>
                                </dxe:ASPxTextBox>
                            </td>
                            <td>
                                JobTitle
                            </td>
                            <td>
                                <dxe:ASPxTextBox ID="ASPxTextBox21" Width="140"
                                    runat="server" Text='<%# Bind("JobTitle")%>'>
                                </dxe:ASPxTextBox>
                            </td>
                            <td>
                               Department
                            </td>
                            <td>
                                <dxe:ASPxComboBox ID="ASPxTextBox22" Width="140" runat="server" Text='<%# Bind("Department")%>'>
                                <Items>
                                <dxe:ListEditItem Text="Account" Value="Account" />
                                </Items>
                                </dxe:ASPxComboBox>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                Remarks
                            </td>
                            <td colspan="5">
                                <dxe:ASPxMemo ID="ASPxMemo1" Width="640" Rows="3" runat="server" Text='<%# Bind("Remark")%>'>
                                </dxe:ASPxMemo>
                            </td>
                        </tr>
                        
                    </table>


                                                </EditForm>
                                                </Templates>
                                            </dxwgv:ASPxGridView> 
                                            <br />
                                                    <dxe:ASPxButton ID="ASPxButton10" Width="100" runat="server" Text="New Contact" Enabled='<%#SafeValue.SafeString(Eval("CustId"),"0")!="0" %>' AutoPostBack="false" UseSubmitBehavior="false" >
                                    <ClientSideEvents Click="function(s,e) {
                                    grd_Cont.AddNewRow();
                                    }" />
                                    </dxe:ASPxButton>

                                        </dxw:ContentControl>
                                    </ContentCollection>
                                </dxtc:TabPage> 
                               </tabpages>
                    </dxtc:ASPxPageControl>
                </EditForm>
            </Templates>
        </dxwgv:ASPxGridView>

        <br />
                                            

</asp:Content>

